package search

var _ Cursor = (*CursorPage)(nil)

// CursorPage 游标分页
type CursorPage struct {
	Cursor int `json:"cursor" query:"cursor"`
	Count  int `json:"count" query:"count"`
}

// GetCursor 获取游标位置
func (c *CursorPage) GetCursor() int {
	if c.Cursor < 0 {
		c.Cursor = 0
	}
	return c.Cursor
}

// GetCount 获取查询数量
func (c *CursorPage) GetCount() int {
	if c.Count <= 0 {
		c.Count = 10
	}
	return c.Count
}

func NewCursor(cursor, count int) *CursorPage {
	return &CursorPage{
		Cursor: cursor,
		Count:  count,
	}
}

type CursorResult struct {
	Cursor     int   `json:"cursor"`
	Count      int   `json:"count"`
	TotalCount int64 `json:"totalCount"`
}

func NewCursorResult(cursor, count int, totalCount int64) *CursorResult {
	return &CursorResult{
		Cursor:     cursor,
		Count:      count,
		TotalCount: totalCount,
	}
}
